<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./封装请求.js"></script>
</head>

<body>
    <button>发起请求</button>
    <h1></h1>
    <script>
        const btn = document.querySelector('button');
        const h1 = document.querySelector('h1');
        btn.addEventListener('click', async () => {
            const res = await myAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            console.log(res);
            Promise.all([myAjax({method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' }),
                         myAjax({method: 'POST', url: 'http://ajax-base-api-t.itheima.net/api/addbook', 
                            data: {
                                bookname: "安徒生童话",
                                author: "安徒生",
                                publisher: "上海出版社"},
            })])
            .then(
                res => h1.innerHTML = '我是主页',
                err => h1.innerHTML = err
            )
        })

    </script>
</body>

</html>